#include <linux/kthread.h>
#include <linux/printk.h>
#include <linux/rwsem.h>
#include <linux/delay.h>

#include <msh/export.h>

static DECLARE_RWSEM(_rwsem);

static int reader(void *param)
{
    while (1)
    {
        down_read(&_rwsem);
        printk("reader\n");
        msleep(2000);
        up_read(&_rwsem);
    }

    return 0;
}

static int writer(void *param)
{
    while (1)
    {
        down_write(&_rwsem);
        printk("writer\n");
        msleep(3000);
        up_write(&_rwsem);
    }

    return 0;
}

static int testrwsem(void)
{
    kthread_run(reader, NULL, "reader");
    kthread_run(writer, NULL, "writer");
    return 0;
}
MSH_CMD_EXPORT(testrwsem, test rwsem);
